Repository navigation
Conversation
…s 7.2 WordPress 7.2 adds random content redirects (/random/, ?random) to core. Stop loading Jetpack's Random Redirect on 7.2 betas and later, and mark jetpack_matt_random_redirect() deprecated.
|
Are you an Automattician? Please test your changes on all WordPress.com environments to help mitigate accidental explosions.
Interested in more tips and information?
|
|
Thank you for your PR! When contributing to Jetpack, we have a few suggestions that can help us test and review your patch:
This comment will be updated as you work on your PR and make changes. If you think that some of those checks are not needed for your PR, please explain why you think so. Thanks for cooperation 🤖 Follow this PR Review Process:
If you have questions about anything, reach out in #jetpack-developers for guidance! Jetpack plugin: The Jetpack plugin has different release cadences depending on the platform:
If you have any questions about the release process, please ask in the #jetpack-releases channel on Slack. |
Gate the jetpack-mu-wpcom copy the same way as the Jetpack plugin, and mark its jetpack_matt_random_redirect() deprecated.
Fixes N/A
Proposed changes
WordPress 7.2 adds random content redirects to core (757cb9c):
/random/,/random/category/news/and friends, plus?randomon any archive or search URL. Core resolves those inWP::main(), beforetemplate_redirect, so on 7.2 it already wins every archive request and Jetpack's Random Redirect only fires on whatever core skips.modules/theme-tools/random-redirect.phpwhen the site runs WordPress7.2-betaor newer. The feature landed during 7.2 alpha, so every beta has it.jetpack-mu-wpcom(features/random-redirect/), gated inJetpack_Mu_Wpcom::load_wpcom_random_redirect().jetpack_matt_random_redirect()deprecated in its docblock. No runtime_deprecated_function()notice: it's atemplate_redirectcallback that still runs on every request on older WordPress, where it's the only implementation.What sites on 7.2+ lose
Deferring to core drops a few things the Jetpack version supported:
?random_post_type=page(or any post type)randomable, which is onlypostby default.?random_cat_id=N/random/category/news/or/category/news/?random).?randomon a single post or page URL/&random,/&random=1jetpack_random_redirect_enabledfilterwp_enable_random_content_redirect.The post type option is the real loss. That said, deferring to core is the more sustainable option: core's version comes with rewrite rules, term, author and post type archives,
noindexheaders and an opt-out filter, and it's maintained where the routing lives. Keeping a second implementation that core pre-empts on most requests anyway would mean shipping behavior that differs depending on which URL a visitor happens to hit.On the function no longer existing on 7.2+: it was removed entirely between 13.6 and 16.1, and themes that depended on it started shipping their own copy (which the existing
function_exists()guard respects). So I didn't add a stub.Related product discussion/links
Does this pull request change what data or activity we track or use?
No.
Testing instructions
You need two sites: one on WordPress 7.2 (nightly) and one on 7.1, both running this branch with a few published posts, a page and pretty permalinks. On Jurassic Ninja, the default core is 7.1; for 7.2 run
wp core update --version=nightly --force.Turn off page caching first, or 302s get cached (
wp config set WP_CACHE false --rawon JN).WordPress 7.2:
wp eval 'var_dump( function_exists( "jetpack_matt_random_redirect" ) );'printsbool(false)./random/,/?randomand/category/<slug>/?random302 to a random post, withX-Robots-Tag: noindex, follow(that header means core handled it)./<some-page>/?randomand/<some-post>/?randomreturn 200 with no redirect. On trunk, Jetpack redirects these.WordPress 7.1:
function_exists( "jetpack_matt_random_redirect" )istrue./?random302s to a random post with noX-Robots-Tagheader (Jetpack handled it)./?random&random_post_type=page302s to a page./random/is a 404, as before.WordPress.com Simple: on a sandboxed Simple site running 7.2,
?randomon a single post or page no longer redirects, and/random/is handled by core. I haven't tested this one; it needs a WordPress.com sandbox.I ran both on Jurassic Ninja with Jetpack trunk plus this branch's two files, using a temporary mu-plugin to confirm which function issued each redirect. PHPUnit wasn't run locally:
Random_Redirect_Testloads the module file directly, so the gate doesn't affect it, but CI runs it against trunk and older WordPress.